package kr.hkit.androidcomplete02.ch16;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.widget.Toast;

public class MyAlertDialogFragment extends DialogFragment {
	
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		Bundle args = getArguments();
		String title = args.getString("title");
		String message = args.getString("message");
		
		return new AlertDialog.Builder(getActivity())
				.setTitle(title)
				.setMessage(message)
				.setPositiveButton("확인", new OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						doClick(which);
					}
				})
				.setNegativeButton("취소", new OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						doClick(which);
					}
				})
				.create();
	}

	protected void doClick(int which) {
		/*-1:positivie -2:negative*/
		switch(which){
		case -1: Toast.makeText(getActivity(), "확인", Toast.LENGTH_LONG).show();
			break;
		case -2: Toast.makeText(getActivity(), "취소", Toast.LENGTH_LONG).show();
			break;
		}
	}

}
